package com.zcxy.fast.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zcxy.fast.anotation.Log;
import com.zcxy.fast.bean.PageQuery;
import com.zcxy.fast.bean.Response;
import com.zcxy.fast.entity.SysMenu;
import com.zcxy.fast.vo.SysMenuVo;
import com.zcxy.fast.service.ISysMenuService;
import io.minio.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;
import java.util.*;
import com.zcxy.fast.bean.TreeNode;

/**
 * 平台-菜单表Controller
 *
 * @author zcc
 * @email  860474958@qq.com
 * @date   2021-02-02 08:48:57
 */
@RestController
@RequestMapping("/api/sysMenu")
@Api(tags = "平台-菜单表管理")
@Slf4j
public class SysMenuController {
    @Autowired
    private ISysMenuService iSysMenuService;

    @Log("获取平台-菜单表数据--分页")
    @PostMapping(value = "/queryPageList")
    @ApiOperation(value = "获取(平台-菜单表)分页数据列表", notes = "获取(平台-菜单表)分页数据列表")
    public Response<IPage<SysMenuVo>> queryPageList(@RequestBody PageQuery<SysMenu> queryVo) {
        return Response.ok(iSysMenuService.queryPageList(queryVo));
    }

    @Log("获取平台-菜单表数据-列表")
    @PostMapping(value = "/queryList")
    @ApiOperation(value = "获取平台-菜单表数据-列表", notes = "获取平台-菜单表数据-列表")
    public Response<List<SysMenuVo>> queryList(@RequestBody SysMenu sysMenu) {
        return Response.ok(iSysMenuService.queryList( sysMenu));
    }


    @Log("添加平台-菜单表数据")
    @PostMapping(value = "/add")
    @ApiOperation(value = "添加平台-菜单表数据", notes = "添加平台-菜单表数据")
    public Response addSysMenu(@RequestBody @Validated @NotNull SysMenu queryVo) {
        iSysMenuService.addSysMenu(queryVo);
        return Response.ok();
    }


    @Log("修改平台-菜单表数据")
    @PostMapping(value = "/update")
    @ApiOperation(value = "修改平台-菜单表数据", notes = "修改平台-菜单表数据")
    public Response updateSysMenu(@RequestBody @Validated @NotNull SysMenu queryVo) {
        iSysMenuService.updateSysMenu(queryVo);
        return Response.ok();
    }


    @Log(value = "批量删除平台-菜单表")
    @ApiOperation("批量删除平台-菜单表")
    @PostMapping("/dels")
    public Response deleteByIds(@RequestBody List<String> ids) {
        iSysMenuService.removeAllSysMenu(ids);
        return Response.ok();
    }

    @Log(value = "根据父id树形结构")
    @ApiOperation("根据父id树形结构")
    @GetMapping("/queryTreeNodeList")
    public Response<List<Map>> queryTreeNodeList(@RequestParam(required = false) String parentId) {

        return Response.ok(iSysMenuService.queryTreeNodeList(parentId));
    }


    @Log(value = "根据父id树形结构")
    @ApiOperation("根据父id树形结构")
    @GetMapping("/queryAllTreeNodeList")
    public Response<List<TreeNode>> queryAllTreeNodeList() {
        return Response.ok(iSysMenuService.queryTreeNodeList());
    }


    @GetMapping(value = "/listMenu")
    @ApiOperation(value = "获取用户菜单", notes = "获取用户菜单")
    public Response<Map<String, Object>> queryUserMenu() {
        Response result = new Response();
        result.setSuccess(true);
        Map<String, Object> map = new HashMap<>();
        map.put("permissions", null);
        map.put("routes", iSysMenuService.queryUserMenu());
        result.setResult(map);
        return result;

    }


}
